package com.neusoft.neuiotms.dcom.repository.problem.impl;

import com.neusoft.bizcore.web.jpa.repository.AbstractRepository;
import com.neusoft.neuiotms.dcom.model.problem.ProblemHandling;
import com.neusoft.neuiotms.dcom.model.problem.QProblemHandling;
import com.neusoft.neuiotms.dcom.repository.problem.CustomizedProblemHandlingRepository;
import com.querydsl.jpa.impl.JPAQuery;

public class CustomizedProblemHandlingRepositoryImpl extends AbstractRepository
        implements CustomizedProblemHandlingRepository {

    @Override
    protected Class<?> getModelClass() {
        return ProblemHandling.class;
    }

    @Override
    public ProblemHandling findByWorkNum(final String workOrderNum) {
        final QProblemHandling qProblemHandling = QProblemHandling.problemHandling;
        final JPAQuery<ProblemHandling> query = this.query().selectFrom(qProblemHandling);
        query.where(qProblemHandling.workOrderNum.eq(workOrderNum))
                .orderBy(qProblemHandling.createTime.desc()).limit(1);
        return query.fetchOne();
    }

}
